<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax请求json数据</title>
    <!-- 全局js -->
    <script src="../static/js/jquery.min.js?v=2.1.4"></script>
    <script src="../static/js/bootstrap.min.js?v=3.3.6"></script>
</head>

<body>
<table class="table table-bordered">
    <tr>
        <th>名字</th>
        <th>开始时间</th>
        <th>是否真实</th>
        <th>设备</th>
    </tr>
</table>

<script>
    $(function(){
        $.ajax({
            url:'../templates/data.json',
            type:'get',
            dataType:'json',
            success:function(data){
                //方法中传入的参数data为后台获取的数据
                for(i in data.data) //data.data指的是数组，数组里是8个对象，i为数组的索引
                {
                    var tr;
                    tr='<td>'+data.data[i].name+'</td>'+'<td>'+data.data[i].startTime+'</td>'+'<td>'+data.data[i].is_true+'</td>'+'<td>'+data.data[i].device+'</td>'
                    $("#tabletest").append('<tr>'+tr+'</tr>')
                }
            },
            error: function() {
                alert('请求失败 ');
            }
        })
    })
</script>

<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>


</body>
</html>